package com.jewaton.auth.commons.service.impl;

import com.jewaton.auth.commons.dao.DistrictDAO;
import com.jewaton.auth.commons.entity.District;
import com.jewaton.auth.commons.service.DistrictService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**   
 *    
 * 地区表service实现类
 *
 */
@Service("districtService")
public class DistrictServiceImpl implements DistrictService {

	private static Log logger = LogFactory.getLog(DistrictServiceImpl.class);
	
	@Resource(name="districtDAO")
	private DistrictDAO districtDAO;
	
	/**
	 * 根据地区ID获取地区名字
	 * @param did 地区的ID
	 * @return 返回地址名称
	 */
	@Override
	public String getDistrictNameByDid(String did) {
		District district = (District)districtDAO.findObjectById(District.class, did);
		return district.getDistrictName();
	}

    @Override
    public District getDistrictByDid(String did) {
        return (District)districtDAO.findObjectById(District.class, did);
    }
	
	@Override
	public String getDistrictZipCodeByDid(String did) {
		District district = (District)districtDAO.findObjectById(District.class, did);
		return district.getZipCode();
	}
	
	/**
	 * 获取所有的地区信息集合
	 */
	@Override
	@Cacheable("system.forever")
	public List<District> getAll(){
		return districtDAO.getAll();
	}
	
	@Override
	public District getByDistrictName(String districtName){
		return this.districtDAO.getByDistrictName(districtName);
	}
	
	/**
	 * 获取所有的地区信息集合
	 */
	@Override
	public List<District> getAllDistrict(){
		return districtDAO.getAllDistrict();
	}
	
	public void setDistrictDAO(DistrictDAO districtDAO) {
		this.districtDAO = districtDAO;
	}
}
